#include <iostream>
#include <vector>

#include <gmp.h>

#include <boost/thread.hpp>  
#include <boost/date_time.hpp>  
#include <boost/shared_ptr.hpp>

class Worker
{
public:
  Worker(int i_)
    : i(i_)
  { }

  void operator()()
  {
    boost::posix_time::seconds workTime(i);
    std::cout << "Worker(" << i << "): running" << std::endl;
    boost::this_thread::sleep(workTime);
    std::cout << "Worker:(" << i << "): finished" << std::endl;    
  }

private:
  int i;
};

typedef boost::shared_ptr<Worker> WorkerPtr;
typedef std::vector<boost::thread*> ThreadVec;

int main()
{
  ThreadVec tv;

  std::cout << "main: startup" << std::endl;

  for (int i = 10; i > 0; --i)
    {
      Worker wi(i);

      boost::thread* workerThread = new boost::thread(wi);
      tv.push_back(workerThread);
    }

  std::cout << "all started" << std::endl;
  
  for (ThreadVec::iterator it = tv.begin(); it != tv.end(); ++it)
    {
      (*it)->join();
    }

  std::cout << "main: done" << std::endl;
}
